<?php
/**
 * indexAction 
 * 
 * 必须实现方法action().并且文件名要与类名保持一致.
 *
 */
class ItemsAction{
	
	public function action($_get){  //$_get是URL参数的数组和$_GET一样.如果不需要可以省略

	require_once "Action/common.php";

	$page_num = 1;
	if($_get['page']){$page_num = $_get['page'];}

	$cid = 30;
	if($_get['cid']){$cid = $_get['cid'];}

	$keyword = DEFKEYWORD;
	if($_get['keyword']){$keyword = $_get['keyword'];}


	//查询淘宝客推广商品(taobao.taobaoke.items.get)

	$Taoapi->method = 'taobao.taobaoke.items.get';

	$Taoapi->fields = 'num_iid,iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,seller_credit_score,item_location,shop_click_url';

	$Taoapi->nick = USERNICK;

	$Taoapi->keyword =  urldecode($keyword);

	$Taoapi->cid = $cid;
	$Taoapi->page_no = $page_num;
	$Taoapi->page_size = PAGE_SIZE;

	$Taoapi->start_credit = '3diamond';

	$Taoapi->end_credit = '5goldencrown';

	$Taoapi->sort = 'commissionNum_desc';

	//需要更多的字段可以登陆 taoapi.com 进行配置生成
	$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();


	echo $TaobaokeData['total_results'];

echo '

<style type="text/css">
<!--
#pages { clear:both;text-align:center; height:28px; line-height:28px; margin-top:20px; margin-bottom:20px; font-size:14px;font-family:"宋体"; }
#pages span {padding:2px 6px;margin:4px 5px 0 0;background:#3366cc;border:1px solid #3366cc; color:#fff; }
#pages a{ padding:2px 6px;margin:4px 5px 0 0; border:1px solid #3366cc; color:#3366cc; }
#pages .active{background:#fff;border:1px solid #3366cc;color:#3366cc;font-weight:bold;padding:2px 5px;margin:4px 5px 0 0;}
#pages a:visited{color:#3366cc;text-decoration:none; }
#pages a:hover{color:#fff;background:#3366cc;border:1px solid #3366cc;}

.pages { margin:10px auto; margin-bottom:10px;}
.pages a { border:1px #E4E4E4 solid; padding:3px 6px 3px 6px; color:#3366cc;}
.pages em { font-size:14px;padding:3px 6px 3px 6px; border:1px #ff3300 solid;}



}
-->
</style>

';

	$page_size		= PAGE_SIZE;
	$pageCurrent	= $page_num;
	$sub_pages		= 10;
	$nums			=  $TaobaokeData['total_results'];

$subPages=new SubPages($page_size,$nums,$pageCurrent,$sub_pages,"/itao/index/items/page/",2);
echo '<div class="pages">';
echo $subPages->subPageCss2();
echo '</div>';

	echo '<pre>';

	//检测API是否遇到错误
	if($Taoapi->getErrorInfo())
	{
		echo "API获取数据遇到错误,错误提示是:";
		
		print_r($Taoapi->getErrorInfo());
	}

	//打印获取到的API数据结果
	print_r($TaobaokeData);

	//查看提交到API的参数
	echo '提交到API的参数:';
	print_r($Taoapi->getParam());

	//查看提交到淘宝的URL地址
	echo '提交到淘宝的URL地址:'.$Taoapi->getUrl();
	echo'</pre>';
	}
}
?>